#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n;
struct Node {
  int pre, nxt;
  int l, r;
} mem[N];
int head = 1, tail = 2, tot;
void del(int id) {
  int pre = mem[id].pre, nxt = mem[id].nxt;
  mem[pre].nxt = nxt, mem[nxt].pre = pre;
}
int add(int l, int r, int pre, int nxt) {
  ++tot;
  mem[tot].l = l, mem[tot].r = r;
  mem[tot].pre = pre, mem[pre].nxt = tot;
  mem[tot].nxt = nxt, mem[nxt].pre = tot;
  return tot;
}
int ans, cnt;
queue<pii> proc;
priority_queue<pii, vector<pii>, greater<pii>> pq;

bool push(int t, int m, int p) {
  for (int id = head; id != tail; id = mem[id].nxt) {
    int nxt = mem[id].nxt;
    int l = mem[id].r + 1, r = mem[nxt].l - 1;
    int sz = r + 1 - l;
    if (sz >= m) {
      int now = add(l, l + m - 1, id, nxt);
      pq.push(pii(t + p, now));
      return true;
    }
  }
  return false;
}
void pop() {
  int t = pq.top().first;
  ans = t;
  while (pq.size() && pq.top().first == t) {
    pii now = pq.top();
    pq.pop();
    del(now.second);
  }
  while (proc.size()) {
    pii now = proc.front();
    if (push(t, now.first, now.second))
      proc.pop();
    else
      break;
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  add(0, 0, 0, 2), add(n + 1, n + 1, 1, 0);
  int t, m, p;
  while (cin >> t >> m >> p) {
    if (!t && !m && !p) break;
    while (pq.size() && pq.top().first <= t) pop();
    if (!push(t, m, p)) proc.push(pii{m, p}), cnt++;
  }
  while (pq.size()) pop();
  cout << ans << endl << cnt;
  return 0;
}